package com.etc;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;


/**
 * @Auther: zhezhe
 * @Date: 2018/10/269:30
 * @Description:
 */
public class JobTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        System.setProperty("HADOOP_USER_NAME","root");

        Configuration configuration = new Configuration();
        configuration.set("mapred.job.tracker","master11:9000");

        Job job = Job.getInstance(configuration);

        job.setJarByClass(JobTest.class);
        job.setMapperClass(AvgSourceMap.class);
        job.setReducerClass(AvgSourceReduce.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        FileInputFormat.addInputPath(job,new Path("hdfs://master11:9000/input/*"));
        FileOutputFormat.setOutputPath(job,new Path("hdfs://master11:9000/outputavg"));

        job.setNumReduceTasks(1);
        System.exit(job.waitForCompletion(true)?0:1);
    }
}
